home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / FSEEK.C < prev    next >
Text File  |  1986-05-18  |  1KB  |  36 lines

  1. /* 1.2  01-08-86                        (fseek.c)
  2. /************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1986        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10. #include "stdio.h"
  11.  
  12. /************************************************************************/
  13.     METACHAR
  14. fseek(fp, offset, where)    /* Position the FILE fp at offset bytes
  15.                    from where. Return EOF on error.    */
  16. /*----------------------------------------------------------------------*/
  17. FAST FILE *fp;
  18. long offset;
  19. {
  20.     long lseek();
  21.     METACHAR fflush();
  22.  
  23.     fp->_flags &= ~_EOF;
  24.     if (fp->_flags & _DIRTY)    /* if something in the write buffer */
  25.     {    if (fflush(fp))
  26.             return EOF;
  27.     }
  28.     else if (where IS CURPOS AND fp->_bptr)    /* or read buffer    */
  29.         offset -= (fp->_bend - fp->_bptr);
  30.     fp->_bptr = fp->_bend = NULL;
  31.     if (lseek(fp->_unit, offset, where) < 0)
  32.         return EOF;
  33.  
  34.     return NULL;
  35. }
  36.